<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>预约记录</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
    <script type="text/javascript">
        var grid = null;
        $(function () {
            $("#ligergrid1").ligerGrid({
                url: '<%=path%>/syssms/sysSmsLog/initReserRecordList.do',
                method : 'get',
                columns: [
                    { display: '手机号', name: 'receivePhone', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '短信内容',minWidth: 650 ,name:'contents', align: 'center',isEllipsis: false,
                        render: function (rowdata, rowindex, value){
                            var h='<div style="width:100%;height:100%;" ondblclick="ondblcontents(\''+rowdata.id+'\',\''+value+'\')"><span class="gridTip" title="'+ value +'">'+ value +'</span></div>';
                            if(value == null){
                                return '<div style="width:100%;height:100%;" ondblclick="ondblcontents(\''+rowdata.id+'\',\'\')"><span></span></div>';
                            }else{
                                return h;
                            }
                        }
                    },
                    { display: '发送时间',minWidth: 150 ,name:'sendDate', align: 'center',
                        render: function (rowdata, rowindex, value){
                            var dateStr = "";
                            if(null != value){
                                var date = new Date(value);
                                dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
                                return '<div style="width:100%;height:100%;" ondblclick="ondblsenddate(\''+rowdata.id+'\')"><span>'+ dateStr +'</span></div>';
                            }else{
                                return '<div style="width:100%;height:100%;" ondblclick="ondblsenddate(\''+rowdata.id+'\')"><span></span></div>';
                            }
                        }
                    },
                    { display: '发送人', name: 'createName', minWidth: 100, align: 'center', enabledSort:true}
                ],
                pageSize:10,
                root:'rows',
                record:'total',
                hideLoadButton : true,
                width: '100%',
                height:'100%',
                heightDiff:-2,
                checkbox:true,
                rownumbers:true,
                fixedCellHeight: false,
                onAfterShowData: function () {
                    $(".gridTip").grid_ligerTip();
                    SetIframe_height ();
                }
            });
            grid = liger.get("ligergrid1");
            grid.setHeight(100);
            $("#searchBar").ligerForm();
            $("#dateform").ligerForm();
            $("#searchBtn").click(function(event) {
                var form = new liger.get("searchBar");
                var data = form.getData();
                console.log(data);
                for (name in data){
                    grid.setParm(name,data[name]);
                };
                if($("#sendDateBegin").val()>$("#sendDateEnd").val()){
                    $.ligerDialog.SQalert({content: "发送时间(起)不能大于发送时间(止)" , SQ_type: "warning" });
                    return;
                }
                grid.reload();
            });
            $("#clearBtn").click(function(event) {
                clearLigerForm("searchBar");
            });
        });
        //删除数据
        function deleteRecord(){
            var selectedRows = grid.getSelectedRows();
            if(selectedRows.length == 0){
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW , SQ_type: "warning" });
                return;
            }

            var _ids = [];
            for ( var index in selectedRows) {
                _ids.push(selectedRows[index].id);
            }
            $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
                if(flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType:'json',
                    data:{ids:JSON.stringify(_ids)},
                    url: '<%=path%>/syssms/sysSmsLog/removeByIds.do',
                    beforeSend: function(){
                        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                    },
                    success:function(msg){
                        wait_dialog.close();
                        if(msg.success == 1){
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                            grid.reload();
                        }else{
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        }
        //短信内容双击事件
        function ondblcontents(_id,_text){
            $.ligerDialog.confirm("是否确认修改?", function (flag) {
                if(flag == false)return;
                $("#modifyContents").val(_text);
                var _dialog = $.ligerDialog.open({
                    target: $("#modifyContentsdiv"),
                    title: '修改内容',
                    width: 600,
                    height: 300,
                    isResize: true,
                    modal: true,
                    buttons: [{ text: '确定', onclick: function (i, d) {
                        var contentstext = $("#modifyContents").val();
                        if (contentstext == '') {
                            top.$.ligerDialog.SQalert({content: "修改内容不能为空",SQ_type: "warning"});
                            return false; //验证不通过，不执行以下代码
                        }
                        $("#modifyContents").val("");
                        _dialog.hide();
                        var wait_dialog;
                        $.ajax({
                            type: 'post',
                            dataType:'json',
                            data:'id='+_id+'&contents='+contentstext,
                            url: '<%=path%>/syssms/sysSmsLog/modify.do',
                            beforeSend: function(){
                                wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                            },
                            success:function(msg){
                                wait_dialog.close();
                                if(msg.success == 1){
                                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                                    grid.reload();
                                }else{
                                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                                }
                            }
                        });
                    }
                    }, { text: '关闭', onclick: function (i, d) {
                        $("#modifyContents").val("");
                        _dialog.hide();
                    }
                    }]
                });
            });
        }
        //预约时间双击事件
        function ondblsenddate(_id){
            $.ligerDialog.confirm("是否确认修改?", function (flag) {
                if(flag == false)return;
                var _dialog = $.ligerDialog.open({
                    target: $("#modifysendDatediv"),
                    title: '修改时间',
                    width: 500,
                    height: 150,
                    isResize: true,
                    modal: true,
                    buttons: [{ text: '确定', onclick: function (i, d) {
                        var modifysendday = $("#modifysendday").val();
                        if (modifysendday == '') {
                            top.$.ligerDialog.SQalert({content: "修改日期不能为空",SQ_type: "warning"});
                            return false; //验证不通过，不执行以下代码
                        }
                        var modifysendhour = $("#modifysendhour").val();
                        alert(modifysendday);
                        alert(modifysendhour);
                        $("#modifysendday").val("");
                        $("#modifysendhour").val("09:00");
                        //$("input:radio[name='hourdate']:checked").removeAttr("checked");
                        //$("input:radio[name='hourdate']").eq(0).attr("checked",true);
                        $("input:radio[name='hourdate']").eq(0).siblings('a').click();
                        _dialog.hide();
                        var wait_dialog;
                        $.ajax({
                            type: 'post',
                            dataType:'json',
                            data:'id='+_id+'&sendday='+modifysendday+'&sendhour='+modifysendhour,
                            url: '<%=path%>/syssms/sysSmsLog/modify.do',
                            beforeSend: function(){
                                wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                            },
                            success:function(msg){
                                wait_dialog.close();
                                if(msg.success == 1){
                                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                                    grid.reload();
                                }else{
                                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                                }
                            }
                        });
                    }
                    }, { text: '关闭', onclick: function (i, d) {
                        $("#modifysendday").val("");
                        $("#modifysendhour").val("09:00");
                        //$("input:radio[name='hourdate']:checked").removeAttr("checked");
                        //$("input:radio[name='hourdate']").eq(0).attr("checked",true);
                        $("input:radio[name='hourdate']").eq(0).siblings('a').click();
                        _dialog.hide();
                    }
                    }]
                });
            });
        }

        //选择时间
        function selecthour(_hour){
            $("#modifysendhour").val(_hour);
        }
    </script>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox col_33">
                    <div class="label">发送时间(起)</div>
                    <div class="field">
                        <input name="sendDateBegin" id="sendDateBegin" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">发送时间(止)</div>
                    <div class="field">
                        <input name="sendDateEnd" id="sendDateEnd" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">手机号</div>
                    <div class="field">
                        <input name="receivePhone" id="receivePhone" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">短信内容关键字</div>
                    <div class="field">
                        <input name="contents" id="contents" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">发送人</div>
                    <div class="field">
                        <input name="createName" id="createName" type="text" class="ui-textbox" value="">
                    </div>
                </div>

                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_1"></i>查询</span>
                    <span id="clearBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_19"></i>清空</span>
                    <span id="delBtn" class="sq-button sq-button-hasicon" onclick="deleteRecord();"><i class="sqBtnIco_7"></i>删除</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                    <span style="float:right;color:red;">注：双击查询出来的内容可修改</span>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>
<div id="modifyContentsdiv" style="display:none">
    修改内容：<br>
    <textarea id="modifyContents" class="ui-textarea l-textarea" rows="10" cols="90" ></textarea>
</div>
<div id="modifysendDatediv" style="display:none">
    <form id="dateform">
        <div class="fieldset1 clearFix">
        <div class="fieldBox col_33">
            <div class="label">请选择日期:</div>
            <div class="field">
                <input name="modifysendday" id="modifysendday" type="text" class="ui-datepicker" value="">
            </div>
        </div>
            <div class="clearFix"></div>
        <div class="fieldBox col_33">
            <div class="label">请选择时间:</div>
            <div class="field">
                <input type="hidden" id="modifysendhour" value="09:00" />
                <input type="radio" name="hourdate" class="hourdate" onclick="selecthour('09:00')" checked  >9点</input>
                <input type="radio" name="hourdate" class="hourdate" onclick="selecthour('10:00')" >10点</input>
                <input type="radio" name="hourdate" class="hourdate" onclick="selecthour('11:00')" >11点</input>
                <input type="radio" name="hourdate" class="hourdate" onclick="selecthour('14:00')" >14点</input>
                <input type="radio" name="hourdate" class="hourdate" onclick="selecthour('15:00')" >15点</input>
                <input type="radio" name="hourdate" class="hourdate" onclick="selecthour('16:00')" >16点</input>
                <input type="radio" name="hourdate" class="hourdate" onclick="selecthour('17:00')" >17点</input>
            </div>
        </div>
        </div>
    </form>
</div>
</body>
</html>
